<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2021/6/16
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="header.jsp"%>
<html>
<head>
    <title>Title</title>
    <!-- 引入 echarts.js -->
    <script src="/static/echarts/echarts.min.js"></script>
</head>

<body>
    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <div id="main1" style="width: 600px;height:400px;"></div>
    <div id="main2" style="width: 600px;height:400px;"></div>

    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('main1'));
        var myChart2 = echarts.init(document.getElementById('main2'));

        $.post(
            '${path}/dept/deptCount',
            function(jsonResult) {
                // [{name:'软件部',value:23},{name:'硬件部'},value:2]
                var list = jsonResult.data;
                // 存放所有部门名字的数组 ['软件部', '硬件部']
                var xArray = [];
                // 存放所有部门员工数量的数组 [23, 2]
                var yArray = [];
                for(var i = 0; i < list.length; i++) {
                    var dept = list[i];
                    xArray.push(dept.name);
                    yArray.push(dept.value);
                }

                // 指定图表的配置项和数据
                var option1 = {
                    title: {
                        text: '部门人数统计'
                    },
                    tooltip: {},
                    legend: {
                        data:['人数']
                    },
                    xAxis: {
                        data: xArray
                    },
                    yAxis: {},
                    series: [{
                        name: '人数',
                        type: 'bar',
                        data: yArray
                    }]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart1.setOption(option1);


                // --------------------------------------
                var option2 = {
                    title: {
                        text: '部门人数统计',
                        subtext: '真实数据',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                    },
                    series: [
                        {
                            name: '人数',
                            type: 'pie',
                            radius: '50%',
                            data: list,  // [{name:'软件部',value:23},{name:'硬件部'},value:2]
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                myChart2.setOption(option2);
            }
        );


    </script>

</body>
</html>
